//
//  MKClassifyViewController.m
//  ManKeCartoon
//
//  Created by dllo on 15/10/16.
//  Copyright © 2015年 ManKe. All rights reserved.
//


#import "MKClassifyViewController.h"

#import "MKBaseHeader.h"
@interface MKClassifyViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>

@end

@implementation MKClassifyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
  
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationController.navigationBar.hidden = YES;
    
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2-50, 24, 100, 30)];
    
    titleLabel.textColor = [UIColor whiteColor];
    [titleLabel setText:@"排行榜"];
    [titleLabel setTextAlignment:NSTextAlignmentCenter];
    [self.navBarView addSubview:titleLabel];
    
    self.classifyScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64*HEIGHT,375*WIDTH , 650*HEIGHT)];
    self.classifyScrollView.contentSize = CGSizeMake(0, 1100);
    self.classifyScrollView.contentOffset = CGPointMake(0, 0);
    self.classifyScrollView.backgroundColor = [UIColor clearColor];
    
//    [self.classifyScrollView setBounces:NO];
    
    [self.view addSubview:self.classifyScrollView];
    
    
    UIButton *popularityButton = [UIButton buttonWithType:UIButtonTypeCustom];
    popularityButton.frame = CGRectMake(0, 0*HEIGHT, 187*WIDTH, 90*HEIGHT);
    [popularityButton setImage:[UIImage imageNamed:[NSString stringWithFormat:@"RQB.png"]] forState:UIControlStateNormal];
    [popularityButton addTarget:self action:@selector(pbutton) forControlEvents:UIControlEventTouchUpInside];
    
    
    UIButton *updateButton = [UIButton buttonWithType:UIButtonTypeCustom];
    updateButton.frame = CGRectMake(187*WIDTH, 0*HEIGHT, 187*WIDTH, 90*HEIGHT);
    [updateButton setImage:[UIImage imageNamed:[NSString stringWithFormat:@"GXB.png"]] forState:UIControlStateNormal];
    [updateButton addTarget:self action:@selector(ubutton) forControlEvents:UIControlEventTouchUpInside];
    
    
    UIButton *monthButton = [UIButton buttonWithType:UIButtonTypeCustom];
    monthButton.frame = CGRectMake(0, 90*HEIGHT, 187*WIDTH, 90*HEIGHT);
    [monthButton setImage:[UIImage imageNamed:[NSString stringWithFormat:@"YPB.png"]] forState:UIControlStateNormal];
    [monthButton addTarget:self action:@selector(mbutton) forControlEvents:UIControlEventTouchUpInside];
    
    
    UIButton *payButton = [UIButton buttonWithType:UIButtonTypeCustom];
    payButton.frame = CGRectMake(187*WIDTH, 90*HEIGHT, 187*WIDTH, 90*HEIGHT);
    [payButton setImage:[UIImage imageNamed:[NSString stringWithFormat:@"FFB.png"]] forState:UIControlStateNormal];
    [payButton addTarget:self action:@selector(ybutton) forControlEvents:UIControlEventTouchUpInside];
    
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.itemSize = CGSizeMake(100*WIDTH, 70*HEIGHT);
    flowLayout.minimumLineSpacing = 35;
    flowLayout.minimumInteritemSpacing = 10;
    flowLayout.sectionInset = UIEdgeInsetsMake(5, 10, 5, 10);
    flowLayout.headerReferenceSize = CGSizeMake(320*WIDTH, 44*HEIGHT);
    
    self.classifyCollection = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 245*HEIGHT - 60*HEIGHT, 375*WIDTH, 900*HEIGHT) collectionViewLayout:flowLayout];
    self.classifyCollection.delegate = self;
    self.classifyCollection.dataSource = self;
    self.classifyCollection.backgroundColor = [UIColor whiteColor];
    
//    [self.classifyCollection setBounces:NO];
    [self.classifyCollection registerClass:[MKClassifyCollectionViewCell class] forCellWithReuseIdentifier:@"MKClassifyCollectionViewCell"];


    
    self.classifyArray = @[@"独家",@"完结",@"VIP",@"日漫",@"韩漫",@"玄幻",@"搞笑",@"恐怖",@"热血",@"悬疑",@"动作",@"恋爱",@"都市",@"校园",@"科幻",@"魔幻",@"少年",@"少女",@"耽美"];
    
    self.Classify_id = @[@"1",@"3",@"2",@"5",@"17",@"15",@"7",@"4",@"11",@"22",@"23",@"19",@"24",@"8",@"25",@"6",@"26",@"12",@"10"];
    
    [self.classifyScrollView addSubview:self.classifyCollection];
    
    [self.classifyScrollView addSubview:payButton];
    [self.classifyScrollView addSubview:monthButton];
    [self.classifyScrollView addSubview:updateButton];
    [self.classifyScrollView addSubview:popularityButton];
    
    [self.classifyCollection registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerView"];

    // Do any additional setup after loading the view.
}


-(void)pbutton
{
    MKListViewController *listVC = [[MKListViewController alloc]init];
    
    listVC.rank_id = @"11";
    listVC.Headname = @"人气榜";
    
    [self.navigationController pushViewController:listVC animated:YES];
}

-(void)ubutton
{
    MKListViewController *listVC = [[MKListViewController alloc]init];
   
    
    listVC.rank_id = @"12";
    listVC.Headname = @"更新榜";
    [self.navigationController pushViewController:listVC animated:YES];
}

-(void)mbutton
{
    MKListViewController *listVC = [[MKListViewController alloc]init];
 
    
    listVC.rank_id = @"15";
    listVC.Headname = @"月票榜";

    [self.navigationController pushViewController:listVC animated:YES];
}

-(void)ybutton
{
    MKListViewController *listVC = [[MKListViewController alloc]init];
    
    
    listVC.rank_id = @"14";
    listVC.Headname = @"VIP榜";

    [self.navigationController pushViewController:listVC animated:YES];
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section;
{
    return self.classifyArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath;

{
    MKClassifyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MKClassifyCollectionViewCell" forIndexPath:indexPath];
    
    cell.backgroundColor = [UIColor clearColor];
    
    [cell.classifyButton setImage:[UIImage imageNamed:[NSString stringWithFormat:@"FL%ld.png",indexPath.row]] forState:UIControlStateNormal];
    
    [cell.classifyButton addTarget:self action:@selector(cbutton:) forControlEvents:UIControlEventTouchUpInside ];
    cell.classifyButton.tag = indexPath.row+400;
    
    [cell.classifyLabel setText:self.classifyArray[indexPath.row]];
    return cell;
    
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
//        UICollectionReusableView *reusableView = [collectionView dequeueReusableCellWithReuseIdentifier:@"headerView" forIndexPath:indexPath];
        
        UICollectionReusableView *reusableView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerView" forIndexPath:indexPath];
        reusableView.backgroundColor = [UIColor whiteColor];
        
        UILabel *headerLabel = [[UILabel alloc]initWithFrame:CGRectMake(155*WIDTH, 4*HEIGHT, 100*WIDTH, 40*HEIGHT)];
        
        
        headerLabel.backgroundColor = [UIColor clearColor];
        
        headerLabel.font = [UIFont boldSystemFontOfSize:20];
        
        headerLabel.text = @"热门分类";
        
        headerLabel.textColor = [UIColor orangeColor];
        
        UIView *wire = [[UIView alloc]initWithFrame:CGRectMake(20*WIDTH,22*HEIGHT,90*WIDTH, 0.8*HEIGHT)];
        wire.backgroundColor = [UIColor grayColor];
        
        UIView *wireView = [[UIView alloc]initWithFrame:CGRectMake(270*WIDTH, 22*HEIGHT, 90*WIDTH, 0.8*HEIGHT)];
        wireView.backgroundColor = [UIColor grayColor];
        
        
        [reusableView addSubview:wireView];
        [reusableView addSubview:wire];
        
        
        [reusableView addSubview:headerLabel];
        
        return reusableView;
    }
    else{
        
        return nil;
    }
    
    
    
}




-(void)cbutton:(UIButton *)cbuttons
{
    MKCategoryViewController *categoryVC =[[MKCategoryViewController alloc]init];
    categoryVC.classify_id = _Classify_id[(cbuttons.tag - 400)];
    categoryVC.titleName = _classifyArray[(cbuttons.tag - 400)];
    [self.navigationController pushViewController:categoryVC animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
